
import javax.servlet.http.*;
import java.sql.*;
import java.io.*;

public class CompanyMessageServlet extends HttpServlet
{
  
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException
  {

     try
       {

       String company_name=request.getParameter("company_name");
 
String college_code=request.getParameter("college_code");
String message=request.getParameter("message");


         response.setContentType("text/html");

         PrintWriter out=response.getWriter();
        out.println(company_name);

           Class.forName("oracle.jdbc.driver.OracleDriver");
         Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","pac","mca"); 
         Statement stmt=con.createStatement();  
ResultSet rs = stmt.executeQuery("SELECT *FROM college_register WHERE college_code='"+college_code+"'");
  if(rs.next())

  {

         PreparedStatement pstmt1=con.prepareStatement("insert into message (message,college_name,company_name) values(?,?,?)");
         
         pstmt1.setString(1,message);
       pstmt1.setString(2,college_code);
       pstmt1.setString(3,company_name);
         pstmt1.executeUpdate();


         
        

         out.println("<html>");
     
         out.println("<body background=\"t11.jpg\">");
         out.println("<table width='70%' height='70%'bdcolor='white'>");
         out.println(" <font size=\"7\"> ");
          out.println("<tr><td>");
         out.println("<br> <b>send Successfully </b>");

         out.println("</td></tr></table>");

         out.println("</font>");

         out.println("</body>");

         out.println("</html>");   

 }
  else
  {
    out.println("<html><body>");out.println("The college should be registered");
  }
     }
    catch(Exception e)
       {
         response.sendError(505,e.getMessage());
         e.printStackTrace();
       }    

  }

}  

 